package monitor;

/**
 * 监控-示例
 * 线程1 - waiting -> runnable -> waiting ...
 * 线程2 - 创建byte数组，演示gc
 * -Xms20m -Xmx20m -Xmn10m -XX:SurvivorRatio=8
 */
public class MonitorDemo {
    final static int _1M = 1024 * 1024;
    public static void main(String[] args) {
        new Thread(() -> {
            for(;;) {
                try {
                    double d = 0;
                    long point = System.currentTimeMillis();
                    for (int i = 0; i < 500_000_000; i++) {
                        d = (d + Math.E) / Math.PI;
                    }
                    System.out.println("计算完毕，用时：" + (System.currentTimeMillis() - point));
                    System.out.println(d);
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(() -> {
            for(;;) {
                byte[] b = new byte[1 * _1M];
                byte[] d = new byte[2 * _1M];
                byte[] e = new byte[4 * _1M];
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
        }).start();
        System.out.println("程序启动成功");
    }
}
